package com.java_base.array_study;

import java.util.Random;
import java.util.Scanner;

public class ArrayTest5 {
    public static void main(String[] args) {
        // 键盘录入一批工号，然后随机排名
        // 1.动态初始化数组
        int[] codes = new int[5];
        // 键盘录入赋值
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < codes.length; i++) {
            System.out.println("请输入第"+(i+1)+"个员工编号：");
            codes[i] = sc.nextInt();
        }

        System.out.print("随机排序前，员工编号顺序：");
        for (int i = 0; i < codes.length; i++) {
            System.out.print(codes[i]+"\t");
        }
        Random rd = new Random();
        int temp = 0;
        for (int i = 0; i < codes.length; i++) {
            int index = rd.nextInt(codes.length);
            temp = codes[index];
            codes[index] = codes[i];
            codes[i] = temp;
        }
        System.out.println();
        System.out.print("随机排序后，员工编号顺序：");
        for (int i = 0; i < codes.length; i++) {
            System.out.print(codes[i]+"\t");
        }
    }
}
